package org.zcl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.zcl.dao.SeckillProductsDao;
import org.zcl.entity.SeckillProducts;
import org.zcl.model.stock.StockRequest;
import org.zcl.service.SeckillProductsService;

/**
 * (SeckillProducts)表服务实现类
 *
 * @author makejava
 * @since 2024-06-18 16:38:45
 */
@Service("seckillProductsService")
public class SeckillProductsServiceImpl extends ServiceImpl<SeckillProductsDao, SeckillProducts> implements SeckillProductsService {

    @Override
    @Transactional(rollbackFor = RuntimeException.class)
    public SeckillProducts stock(StockRequest stockRequest) {
        SeckillProducts seckillProducts = this.getById(stockRequest.getProductId());
        seckillProducts.setStock(seckillProducts.getStock() - stockRequest.getNum());
        this.updateById(seckillProducts);
        return seckillProducts;
    }
}
